<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>修改多个 p 元素</title>
</head>
<body>
    <input type="button" value="点击效果" id="btn">
    <div id="dv1">
        <p>I'm a lab p.</p>
        <p>I'm a lab p.</p>
        <p>I'm a lab p.</p>
        <p>I'm a lab p.</p>
        <p>I'm a lab p.</p>
    </div>
    <div id="dv2">
        <p>I'm a lab p, too.</p>
        <p>I'm a lab p, too.</p>
        <p>I'm a lab p, too.</p>
        <p>I'm a lab p, too.</p>
        <p>I'm a lab p, too.</p>
    </div>

    <script>
    document.getElementById("btn").onclick = function(){
        var pObj = document.getElementById("dv1").getElementsByTagName("p");
        for (var i=0; i<pObj.length; i++) {
            pObj[i].innerText = "I was changed by a button.";
        }
    };
    
    
    </script>
</body>
</html>